/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package ex;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>Project: jse2204 - T13
 * <p>Powered by webrx On 2022-10-09 09:16:44
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T13 {
    ReentrantLock o = new ReentrantLock(true);

    void m1() {
        String t = Thread.currentThread().getName();
        System.out.println(t + "启动...");
        for (int i = 0; i < 5; i++) {
            o.lock();
            try{
                TimeUnit.SECONDS.sleep(1);
            }catch(Exception e){
                e.printStackTrace();
            }
            System.out.printf("%s:%d%n", t, i);
            o.unlock();
        }
    }

    public static void main(String[] args) {
        T13 tt = new T13();
        new Thread(tt::m1, "t1").start();
        new Thread(tt::m1, "t2").start();
        new Thread(tt::m1, "t3").start();
        new Thread(tt::m1, "t4").start();
    }
}
